package com.gr.catanddog_common.utils;

import com.alibaba.fastjson2.JSON;
import com.gr.catanddog_common.utils.tokenUtils.TokenPlayLoad;

import java.util.Base64;

/**
 * @author 大睡大唬
 * @version 1.0
 * @description: TODO
 * @date 2024/3/4 9:24
 */
public class UnbindTokenUtil {
    public static void main(String[] args) {
        String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiLlpKfnnaHlpKfllKwiLCJleHAiOiIxNzA5MDkwOTE5MjI1IiwiaWF0IjoiMTcwOTA5MDkxNTYyNSJ9.CccsWEEzS/cPKatkjCT9+Yl9m5KX2Uf+n3Y2Z/XQFXU=";
        System.out.println(token);
        StringBuffer sb = new StringBuffer();
        String[] split = token.split("\\.");
        byte[] decode = Base64.getDecoder().decode(split[1].getBytes());
        String s = new String(decode);
        TokenPlayLoad tokenPlayLoad = JSON.parseObject(s, TokenPlayLoad.class);
        tokenPlayLoad.setData("123456");
        split[1] = Base64.getEncoder().encodeToString(JSON.toJSONBytes(tokenPlayLoad));
        s = split[0]+'.'+split[1]+'.'+split[2];
        System.out.println(s);
        byte[] decode1 = Base64.getDecoder().decode(split[1].getBytes());
        String s1 = new String(decode);
        TokenPlayLoad tokenPlayLoad1 = JSON.parseObject(s1, TokenPlayLoad.class);
        tokenPlayLoad1.setData(null);
        split[1] = Base64.getEncoder().encodeToString(JSON.toJSONBytes(tokenPlayLoad1));
        s1 = split[0]+'.'+split[1]+'.'+split[2];
        System.out.println(s1);
    }
}
